<template>
  <div class="manage">
    <div class="flow-path">
      <template v-for="(item, index) in flowList">
        <template v-if="item.e0302 === '99'">
          <trouble
            :info="item"
            :key="index"
            :flag="index !== flowList.length - 1"
          ></trouble>
        </template>
        <!-- 任务接收 -->
        <template v-if="item.e0302 === '01'">
          <task-accept
            :info="item"
            :key="index"
            :flag="index !== flowList.length - 1"
          ></task-accept>
        </template>
        <!-- 处置反馈 -->
        <template v-if="item.e0302 === '02'">
          <feedback
            :info="item"
            :key="index"
            :flag="index !== flowList.length - 1"
          ></feedback>
        </template>
        <!-- 审核 -->
        <template v-if="item.e0302 === '03'">
          <pt-examine
            :info="item"
            :key="index"
            :flag="index !== flowList.length - 1"
          ></pt-examine>
        </template>
        <!-- 驳回 -->
        <template v-if="item.e0302 === '04'">
          <pt-reject
            :info="item"
            :key="index"
            :flag="index !== flowList.length - 1"
          ></pt-reject>
        </template>
        <!-- 流转 -->
        <template v-if="item.e0302 === '05'">
          <pt-roam
            :info="item"
            :key="index"
            :flag="index !== flowList.length - 1"
          ></pt-roam>
        </template>
        <!-- 流转接收 -->
        <template v-if="item.e0302 === '06'">
          <roam-accept
            :info="item"
            :key="index"
            :flag="index !== flowList.length - 1"
          ></roam-accept>
        </template>
        <!-- 任务已流转 -->
        <template v-if="item.e0302 === '07'">
          <transferred
            :info="item"
            :key="index"
            :flag="index !== flowList.length - 1"
          ></transferred>
        </template>
        <!-- 领导审阅 -->
        <template v-if="item.e0402 === '1'">
          <approve
            :info="item"
            :key="index"
            :flag="index !== flowList.length - 1"
          ></approve>
        </template>
        <!-- 催办 -->
        <template v-if="item.e0402 === '3'">
          <press-tackle
            :info="item"
            :key="index"
            :flag="index !== flowList.length - 1"
          ></press-tackle>
        </template>
         <!-- 责任领导变更 -->
         <template v-if="item.e0402 === '5'">
          <response
            :info="item"
            :key="index"
            :flag="index !== flowList.length - 1"
          ></response>
        </template>
        <!-- 科室领导变更 -->
        <template v-if="item.e0402 === '6'">
          <department
            :info="item"
            :key="index"
            :flag="index !== flowList.length - 1"
          ></department>
        </template>
      </template>
    </div>
    <pt-stage
      v-if="oprateShow"
      :e0301="currentProcess"
      :id="e0201"
      :is-tackle="isTackle"
      :is-roam="isRoam"
      @managerModalClose="$emit('managerModalClose')"
    ></pt-stage>
    <my-msg
      style="margin-top: 10px"
      :msgList="myMsgList"
      :oprate-show="oprateShow"
      @delMsg="delMsg"
    ></my-msg>
    <other-msg :msgList="otherMsgList"></other-msg>
    <operate
      v-if="oprateShow && isAudit"
      :is-only-reject="isOnlyReject"
      :id="e0201"
      style="margin-top: 10px"
      @managerModalClose="$emit('managerModalClose')"
    ></operate>
  </div>
</template>

<script>
import { updateE0219To0 } from "@/services/system/flowPath";
import trouble from "./components/trouble.vue";
import taskAccept from "./components/taskAccept.vue";
import feedback from "./components/feedback.vue";
import ptRoam from "./components/ptRoam.vue";
import roamAccept from "./components/roamAccept.vue";
import pressTackle from "./components/pressTackle.vue";
import ptReject from "./components/ptReject.vue";
import ptExamine from "./components/ptExamine.vue";
import ptStage from "./components/ptStage.vue";
import myMsg from "./components/myMsg.vue";
import otherMsg from "./components/otherMsg.vue";
import approve from "./components/approve.vue";
import operate from "./components/operate.vue";
import transferred from "./components/transferred.vue";
import response from "./components/response.vue";
import department from "./components/department.vue";

export default {
  name: "pitfallManage",
  props: {
    data: {
      type: Object,
      default: () => {},
    },
    e0201: {
      type: [String, Number],
      default: "",
    },
    oprateShow: {
      type: Boolean,
      default: true,
    },
  },
  components: {
    trouble,
    taskAccept,
    feedback,
    ptRoam,
    roamAccept,
    pressTackle,
    ptExamine,
    ptReject,
    ptStage,
    myMsg,
    otherMsg,
    approve,
    operate,
    transferred,
    response,
    department,
  },
  data() {
    return {
      flowList: [],
      myMsgList: [],
      otherMsgList: [],
      isRoam: false,
      isAudit: false,
      isTackle: false,
      currentProcess: null,
      isOnlyReject: false,
    };
  },
  mounted() {
    this.getInfo();
  },
  methods: {
    getInfo() {
      let result = JSON.parse(JSON.stringify(this.data)) || {};
      this.isRoam = result.allowMove === "1";
      this.isAudit = result.allowAudit === "1";
      this.isTackle = result.allowToDo === "1";
      this.currentProcess = result.currentProcess;
      let info = result.dangerInfo || {};
      this.isOnlyReject = info.e0220 == "1"; // 只能驳回
      let list =
        result.dangerHandleProcessBuild || result.dangerHandleProcess || [];
      this.flowList = [{ ...info, e0302: "99" }, ...list];
      this.myMsgList = result.myMessage || [];
      this.otherMsgList = result.otherMessage || [];
      if (info.e0219 == "1") {
        this.showTips();
      }
    },
    delMsg(index) {
      this.myMsgList.splice(index, 1);
    },
    showTips() {
      let _this = this;
      this.$warning({
        title: "温馨提示",
        content: `问题描述已更新，请驳回。`,
        centered: true,
        okText: "确定",
        onOk() {
          _this.noticeClosePoup();
        },
      });
    },
    noticeClosePoup() {
      this.$http.post(updateE0219To0, {
        e0201: this.e0201,
      });
    },
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="less" scoped>
</style>
